package controller;

/**
 * The RegistrationController provides all the methods needed to update the RegistrationDisplay class
 * and receive input from it. It acts as an intermediate between the registration GUI and the server.
 */

import java.rmi.RemoteException;

import gui.Display;
import gui.RegistrationDisplay;
import model.user.UserSettings;

public class RegistrationController extends Controller {
	/**
	 * Constructor method. Sets the Display based on the previous Display object.
	 * @param display The previous Display object.
	 */
	public RegistrationController(Display display) {
		RegistrationDisplay registrationDisplay = new RegistrationDisplay(this, display);
		setDisplay(registrationDisplay);
	}
	
	/**
	 * Swtich back to the login screen by giving control the the login controller
	 */
	public void returnToLogin() {
		Controller loginController = new LoginController(display);
		this.giveControlTo(loginController);
	}

	/**
	 * Create a new account  from the given information and return to the login screen
	 * @param username the username of the new user
	 * @param password the password of the new user
	 * @param userSettings the settings of the new user 
	 * @throws RemoteException
	 */
	public void confirmRegistration(String username, String password, UserSettings userSettings) throws RemoteException {
		serverRemote.createAccount(username, password, userSettings);
		this.returnToLogin();
	}
}
